// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';

/** 获取当前的用户 GET /api/currentUser */
export async function getCurrentUser(options?: { [key: string]: any }) {
  return request<API.CurrentUser>('/users/current', {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      token: `${localStorage.getItem('token')}`,
    },
    method: 'GET',
    ...(options || {}),
  });
}

/** 退出登录接口 POST /api/login/outLogin */
export async function outLogin(options?: { [key: string]: any }) {
  return request<Record<string, any>>('/api/login/outLogin', {
    method: 'POST',
    ...(options || {}),
  });
}

/** 登录接口 POST /api/login/account */
export async function login(body: API.LoginParams, options?: { [key: string]: any }) {
  return request<API.LoginResult>('/tokens', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 注册接口 POST /users */
export async function register(body: API.RegisterParams, options?: { [key: string]: any }) {
  return request<API.RegisterResult>('/users', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 获取全部种类信息接口 GET /categories  */
export async function CategoryInfo(options?: { [key: string]: any }) {
  return request<API.CategoryInfo>('/categories', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    ...(options || {}),
  });
}

/** 获取全部product信息接口 GET /product  */
export async function AllProductInfo(options?: { [key: string]: any }) {
  return request<API.ALLProductInfo>('/product', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    ...(options || {}),
  });
}

/** 获取商品信息 GET /items */
export async function getItemById(itemId: string, options?: { [key: string]: any }) {
  const urlWithId = `/items/${encodeURIComponent(itemId)}`;
  return request<API.ItemInfo>(urlWithId, {
    headers: {
      'Content-Type': 'application/json',
      token: `${localStorage.getItem('token')}`,
    },
    method: 'GET',
    ...(options || {}),
  });
}

/** 获取当前的用户的购物车信息 GET /carts */
export async function getCartInfo(options?: { [key: string]: any }) {
  return request<API.CartInfo>('/carts', {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      token: `${localStorage.getItem('token')}`,
    },
    method: 'GET',
    ...(options || {}),
  });
}

/** 获取当前的用户的订单记录信息 GET /order */
export async function getOrderListInfo(options?: { [key: string]: any }) {
  return request<API.OrderList>('/order', {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      token: `${localStorage.getItem('token')}`,
    },
    method: 'GET',
    ...(options || {}),
  });
}

/** 新建订单 POST /orders */
export async function newOrder(body: API.NewOrderParams, options?: { [key: string]: any }) {
  return request<API.OrderResult>('/order', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      token: `${localStorage.getItem('token')}`,
    },
    data: body,
    ...(options || {}),
  });
}
